/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cx1.service.impl;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.cx1.model.Featured;
import org.cx1.model.FeaturedList;
import org.cx1.model.Listing;
import org.cx1.model.ds.MockDS;
import org.cx1.model.utils.SearchOption;
import org.cx1.model.utils.ServiceResponse;
import org.cx1.service.api.IFeaturedService;

/**
 *
 * @author ECH
 */
public class MFeaturedService implements IFeaturedService {

    @Override
    public ServiceResponse<List<FeaturedList>> readAllFeaturedList(int offset, int limit) {
        ServiceResponse<List<FeaturedList>> response = new ServiceResponse<List<FeaturedList>>();
        List<FeaturedList> featuredList = new ArrayList<FeaturedList>();
        try {
            if (MockDS.getFeaturedList() != null && MockDS.getFeaturedList().size() > 0) {
                for (FeaturedList record : MockDS.getFeaturedList()) {
                    featuredList.add(record);
                }
            }
            response.setSuccessful(true);
            response.setResponse(featuredList);
        }
        catch (Exception ex) {
            response.setException(ex);
            response.setMessage(ex.getMessage());
            response.setSuccessful(false);
        }
        return response;
    }

    @Override
    public ServiceResponse<String> createFeaturedList(String id, FeaturedList featuredList) {
        ServiceResponse<String> response = new ServiceResponse<String>();
        try {            
            FeaturedList entry = new FeaturedList();
            
            entry.setId(id);                        
            entry.setListingID(featuredList.getListingID());
            
            MockDS.getFeaturedList().add(entry);
            
            response.setResponse(id);
            response.setSuccessful(true);            
        } 
        catch (Exception ex) {
            response.setResponse(null);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);
            ex.printStackTrace();            
        }
        return response;
    }

    @Override
    public ServiceResponse<Boolean> deleteFeaturedList(String id) {
        ServiceResponse<Boolean> response = new ServiceResponse<Boolean>();
        boolean success = false;
        try {            
            List<FeaturedList> records = MockDS.getFeaturedList();
            if (records != null && records.size() > 0) {
                
                for (int i = 0; i < records.size(); i++) {
                    FeaturedList record = records.get(i);
                    
                    if (StringUtils.equalsIgnoreCase(record.getId(), id)) {
                        records.remove(i);
                        success = true;
                        break;
                    }
                }
            }            
            response.setResponse(success);
            response.setSuccessful(true);
        } 
        catch (Exception ex) {
            response.setResponse(null);
            response.setSuccessful(false);
            response.setMessage(ex.getMessage());
            response.setException(ex);
            ex.printStackTrace();            
        }
        return response; 
    }

    @Override
    public ServiceResponse<String> create(Featured featured) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<Boolean> delete(String id) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<List<Featured>> readAll(String city, String termType, int offset, int limit) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<List<Featured>> randomFeatured(String city, String termType, int max) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<List<Listing>> randomFeaturedListings(String city, String termType, int max) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<List<Listing>> randomFeaturedListings(String city, String termType, int max, SearchOption option) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<Boolean> checkMaxReached(String city, String termType) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<Boolean> checkExisting(String listingID, String city, String termType) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<Boolean> checkListingValid(String listingID) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public ServiceResponse<List<Featured>> readAll(int offset, int limit) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
